import java.util.ArrayList;
import java.util.List;
import java.util.Random;


public class ArrayListVSLinkedList {
    private static final int NUMBER_OF_ADDING = 1000;

    public static void main(String[] args) {
        test(false);
        test(true);
        

    }
    
    public static void test(boolean sysout) {
        List<String> arrayList = new ArrayList<String>();
        List<String> linkedList = new ArrayList<String>();
        Random random = new Random();
        String str = null;
        long diff = 0l;
        int iteration = 0;
        while(true) {
            iteration++;
            
            diff = testList(linkedList, iteration) - testList(arrayList, iteration);
            if (sysout)
                System.out.println(diff);
            if (iteration > 50)
                break;
        }
    }
    
    public static long testList(List<String> list, int iterations) {
        Random random = new Random();
        String str = null;
        long duration = System.nanoTime();
        for (int i = 0; i < iterations; ++i) {
            str = String.valueOf(random.nextLong());
            list.add(0, str);
        }
        return duration - System.nanoTime();
    }
}
